{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "416728b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8eb20b2c",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"data/ssd_failure_tag.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "820e0203",
   "metadata": {},
   "outputs": [],
   "source": [
    " dict_ = {'A3': '480GB',\n",
    "                'A6': '800GB',\n",
    "                'A4': '240GB',\n",
    "                'A1': '480GB',\n",
    "                'A5': '480GB',\n",
    "                'A2': '800GB',\n",
    "                'B2': '1920GB',\n",
    "                'B3': '1920GB',\n",
    "                'B1': '480GB',\n",
    "                'C1': '1920GB',\n",
    "                'C2': '960GB'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "cdd3621e",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['capacity'] = df['model']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6d6e4924",
   "metadata": {},
   "outputs": [],
   "source": [
    "for key, value in dict_.items():\n",
    "            df['capacity'] = df['capacity'].replace(key, value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d09bfbc5",
   "metadata": {},
   "outputs": [],
   "source": [
    "grouped = df.groupby('capacity')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "87ef8989",
   "metadata": {},
   "outputs": [],
   "source": [
    "res_df = pd.DataFrame(columns=['capacity','failure','all','percentage'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2005a9d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "row = 0\n",
    "for col, group in grouped:\n",
    "    res_df.loc[row] = [col,group.shape[0], '','']\n",
    "    row = row + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d61801b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_all = pd.read_csv(\"data/20191231.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "30a87d02",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_all['capacity'] = df_all['model']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "626e6330",
   "metadata": {},
   "outputs": [],
   "source": [
    "grouped = df_all.groupby('capacity')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c125b18b",
   "metadata": {},
   "outputs": [],
   "source": [
    "for key, value in dict_.items():\n",
    "            df_all['capacity'] = df_all['capacity'].replace(key, value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "fc92e96b",
   "metadata": {},
   "outputs": [],
   "source": [
    "row = 0\n",
    "for col, group in grouped:\n",
    "    res_df.iloc[row, 2] = group.shape[0]\n",
    "    res_df.iloc[row, 3] = res_df.iloc[row, 1] * 100 / res_df.iloc[row, 2]\n",
    "    row = row + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "c0607ea8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  capacity failure     all percentage\n",
      "0   1920GB   12921  249886   5.170758\n",
      "1    240GB     461   35722   1.290521\n",
      "2    480GB    2765  333158   0.829937\n",
      "3    800GB    1109   67640   1.639562\n",
      "4    960GB    1131   19776   5.719053\n"
     ]
    }
   ],
   "source": [
    "print(res_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "51ab863f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='Capacity', ylabel='RFR'>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAEKCAYAAAAYd05sAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6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+6bKaSqHmIYzO2iGgaXuojhU5Gvb5ucCKysqrXzc7jShhnw2pEE+P0kNzF8mcMBzHbbfKNmxyb6OMMwDwDHtVESv8ow5vcLkuwJHFBVlwJU1fer6l/mKPs8hvGNYBjp9CPzckTSJhjw6tEq4KgNLH89w+h+R9UwIug3mR00bv0xOyrJbsCfAadV1QuBP2cjg8zNpaq+AXwzw1dEHs3wzVnSqAx49egqYNckS2YWJPkJhq9Qu7+qHk5yXJufsSjJT7fp/8Dw9XIzYf6tNqb+afDYt2Pdk+SUtu9d8/jvoP0uw/cQTPoQw7uDv6qqR7fyGKU5GfDqTg0j6J0KnNhuk1zFMOTzlcB06255I8NoijNuA34lyWrgR4AP1PAVjX/OMKLgZxm+53fGG4Bfbd09X2T4opNJVwOHzlxkbcsuA56K3TPaRhxNUju8DF9neHm7kDpmOdMM33D0kjHLkWbsPPcmkrZWkrMYvsj59XNtK80Xz+AlqVP2wUtSpwx4SeqUAS9JnTLgJalTBrwkdcqAl6RO/X/ZNYvvw6g8FAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "res_df.plot(x = 'capacity', y = 'percentage', kind='bar', rot = 0, xlabel = 'Capacity', ylabel = 'RFR', legend = None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50d20785",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
